/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.math.ColorRGBA;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.controls.ButtonClickedEvent;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
 * @date 2024年7月26日21点17分
 * @author JohnKkk
 */
public class NiftyGui extends SimpleApplication implements ScreenController{

    private int m_Id;
    public NiftyGui(){
        m_Id = (int) (Math.random() * 10.0f);
    }

    @Override
    public String toString() {
        return "NiftyGui{" + "m_Id=" + m_Id + '}';
    }
    
    public static void main(String[] args) {
        NiftyGui niftyGuiLabel = new NiftyGui();
        niftyGuiLabel.start();
    }

    @Override
    public void simpleInitApp() {
        // 设置默认背景色
        getViewPort().setBackgroundColor(ColorRGBA.DarkGray);
        
        // 初始化Nifty
        NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(
                assetManager,
                inputManager,
                audioRenderer,
                guiViewPort);
        Nifty nifty = niftyDisplay.getNifty();
        // 将NiftyGUI显示对象添加到JME3中
        guiViewPort.addProcessor(niftyDisplay);
        
        nifty.fromXml("Interface/Test.xml", "GScreen0");
        
        // 禁用flyCam并显示鼠标
        flyCam.setEnabled(false);
        inputManager.setCursorVisible(true);
    }
    @NiftyEventSubscriber(id = "Next")
    public final void onNext(final String id, final ButtonClickedEvent buttonClickedEvent){
        Nifty nifty = buttonClickedEvent.getButton().getElement().getNifty();
        nifty.gotoScreen("GScreen1");
    }

    @Override
    public void bind(Nifty arg0, Screen screen) {
        System.out.println("screen:" + screen.getScreenId() + ";control:" + screen.getScreenController().toString());
    }

    @Override
    public void onStartScreen() {
    }

    @Override
    public void onEndScreen() {
    }
    
}
